package main

import (
	"net"
	"fmt"
	"google.golang.org/grpc"
	"git.oschina.net/YPTArch/appcenter/grpc/pd"
	"golang.org/x/net/context"
	"git.oschina.net/YPTArch/appcenter/models"
	"google.golang.org/grpc/reflection"
)

const (
	port = "192.168.1.100:10001"
)

// server is used to implement helloworld.GreeterServer.
type server struct{}

func(s *server) GetApplication(ctx context.Context, in *pb.ApplicationRequest) (*pb.ApplicationReply, error) {
	app,err:= models.ApplicationService.GetByAppId(in.AppId)
	return &pb.ApplicationReply{AppId: app.AppId, AppName: app.AppName, AppDesc: app.AppDesc, IsDel: app.IsDel}, err
}


func main() {
	lis, err := net.Listen("tcp", port)
	if err != nil {
		fmt.Printf("failed to listen: %v", err)
	}
	s := grpc.NewServer()
	pb.RegisterApplicationServer(s, &server{})
	//pb.RegisterGreeterServer(s, &server{})
	// Register reflection service on gRPC server.

	reflection.Register(s)
	if err := s.Serve(lis); err != nil {
		fmt.Printf("failed to serve: %v", err)
	}
}